package com.bsoft.gol.hcs.specialist.dao;

import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.HibernateSupportDelegateDAO;
import ctd.persistence.support.hibernate.template.AbstractHibernateStatelessResultAction;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import ctd.persistence.support.hibernate.template.HibernateStatelessResultAction;
import org.hibernate.Query;
import org.hibernate.StatelessSession;
import com.bsoft.gol.hcs.specialist.entity.FollowUpPathRouteExplandEntity;

import java.util.List;

/**
 * @author hekr22831
 * @description 院后随访计划表单和宣教
 * @date 2022/5/26.8:52
 */
public abstract class FollowUpPathRouteExplandDAO extends HibernateSupportDelegateDAO<FollowUpPathRouteExplandEntity> {

    /**
     * 查询-院后随访计划表单和宣教
     * @param followPlanId
     * @return
     */
    @DAOMethod(sql = "from FollowUpPathRouteExpland where followPlanId=:followPlanId")
    public abstract List<FollowUpPathRouteExplandEntity> findFupreByFollowPlanId(@DAOParam("followPlanId") Long followPlanId);

    /**
     * 根据随访计划id删除随访计划表
     * @param followPlanId
     */
    @DAOMethod(sql = "delete from FollowUpPathRouteExpland where followPlanId=:followPlanId")
    public abstract void deleteFollowPlanByFPId(@DAOParam("fusPathRouteId") Long followPlanId);

    /**
     * 根据院后随访id删除随访计划表
     * @param fusPathRouteId
     */
    @DAOMethod(sql = "delete from FollowUpPathRouteExpland where fusPathRouteId=:fusPathRouteId")
    public abstract void deleteFollowPlanByFprId(@DAOParam("fusPathRouteId") long fusPathRouteId);

    public void insert(FollowUpPathRouteExplandEntity fupre) {
        HibernateStatelessResultAction<Void> action = new AbstractHibernateStatelessResultAction<Void>() {
            @Override
            public void execute(StatelessSession statelessSession) {
                String sql ="INSERT INTO follow_up_path_route_expland(follow_plan_id,form_education_id,form_education_name,content_type,fus_path_route_id) " +
                        "VALUES(:followPlanId,:formEducationId,:formEducationName,:contentType,:fusPathRouteId);";
                Query query = statelessSession.createSQLQuery(sql);
//                query.setParameter("expandId", fupre.getExpandId());
                query.setParameter("followPlanId", fupre.getFollowPlanId());
                query.setParameter("formEducationId", fupre.getFormEducationId());
                query.setParameter("formEducationName", fupre.getFormEducationName());
                query.setParameter("contentType", fupre.getContentType());
                query.setParameter("fusPathRouteId", fupre.getFusPathRouteId());
                query.executeUpdate();
            }
        };
        HibernateSessionTemplate.instance().execute(action);
    }
}
